package com.lsh.airticket.controller;

import com.lsh.airticket.dto.Result;
import com.lsh.airticket.entity.Passenger;
import com.lsh.airticket.service.PassengerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lsh
 * @date 2021/2/19
 **/
@RestController
@RequestMapping("/users")
public class PassengerController {

    @Autowired
    PassengerService passengerService;

    /**
     * 添加一条 passenger信息。
     * @param passenger
     * @return
     */
    @PostMapping("/passenger/addPassenger")
    public Result addPassenger(@RequestBody Passenger passenger) {
        passengerService.addPassenger(passenger);
        return Result.result();
    }

    /**
     * 通过 userId 查找 该用户下面的 乘客 列表
     * @return
     */
    @GetMapping("/passenger/findPassengerByUserId")
    public Result findPassengerByUserId(Integer userId) {
        List<Passenger> passengerList = passengerService.findPassengerByUserId(userId);
        return Result.result().addData("passengerList", passengerList);
    }
}
